classdef MultiLabelWrapper < RegularizedMultiLabelSubsetwiseAndFeaturewiseFeatureSelection
    %MULTILABELWRAPPER Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
    end
    
    methods
        function [ this ] = MultiLabelWrapper( name )
            this.setName('mwrapper');
        end
    end
    
    methods
        function [  ] = build( this, X, Y )
            mlknn = MultiLabelKNearestNeighbor();
            
            nFeature = size(X, 2);
            nLabel = size(Y, 2);
            zRemainId = true(1, nFeature);
            zRank = zeros(1, nFeature);
            ithFeature = nFeature;
            while nnz(zRemainId) > 0
                fprintf(1, '%d, ', nnz(zRemainId));
                z_score = -inf(1, nFeature);
                for iFeature = find(zRemainId)
                    z_id = zRemainId;
                    z_id(iFeature) = false;
                    X_i = X(:, z_id);
                    mlknn.build(X_i, Y);
                    applyResult_i = mlknn.apply(X_i, Y);
                    z_score(iFeature) = HammingLoss.calc(Y, applyResult_i.Y_hat, applyResult_i.Y_out);
                end
                [~, max_id] = max(z_score); max_id = max_id(1);
                zRemainId(max_id) = false;
                zRank(max_id) = ithFeature;
                ithFeature = ithFeature - 1;
            end
            this.model.zRank = zRank;
        end
    end
    
end

